//
//  MyApiClient.m
//  Waiter
//
//  Created by test on 9/6/12.
//  Copyright (c) 2012 logigear. All rights reserved.
//

#import "MyApiClient.h"
#import "Reachability.h"
#import "AFNetworking.h"
#import "Constant.h"
@implementation MyApiClient

+(MyApiClient*)sharedClient
{
    
    static MyApiClient *_sharedClient = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _sharedClient = [[MyApiClient alloc] initWithBaseURL:[NSURL URLWithString:kAPI_URL_BASE]];
    });
    
    return _sharedClient;
}
- (id)initWithBaseURL:(NSURL *)url {
    self = [super initWithBaseURL:url];
    if (!self) {
        return nil;
    }
    [self registerHTTPOperationClass:[AFJSONRequestOperation class]];
    
    // Accept HTTP Header; see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1
	[self setDefaultHeader:@"Accept" value:@"application/x-www-form-urlencoded"];
    return self;
}

+(BOOL)checkConnection {
    Reachability *reachability = [Reachability reachabilityForInternetConnection];	
	NetworkStatus remoteHostStatus = [reachability currentReachabilityStatus];
	
    if (remoteHostStatus == NotReachable) {
		//no internet connection
		return FALSE;
    }  else {
        return TRUE;
    }
}

@end
